home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
Source
/
tarsrc Folder
/
menu.c
< prev
next >
Wrap
Text File
|
1993-11-27
|
6KB
|
320 lines
/*
* Macintosh Tar
*
* Written by Craig Ruff.
*
* Menu handling routines.
*/
#include "tar.h"
#include <Resources.h>
/*
* Resource IDs for menus
*/
#define appleID 128
#define fileID 129
#define editID 130
#define optionID 131
/*
* Index for each menu
*/
#define appleMenu 0
#define fileMenu 1
#define editMenu 2
#define optionMenu 3
#define menuCount 4
/*
* Item in Apple Menu
*/
#define aboutItem 1
/*
* Items in File Menu
*/
#define createItem 1 /* Create archive */
#define extractItem 2 /* Extract archive */
#define listItem 3 /* List archive */
#define closeItem 5 /* Close (only for Desk Acc) */
#define pgsetItem 6 /* Page setup */
#define prefItem 7
#define quitItem 9
/*
* Items in Edit Menu
*
* For use by Desk Accessories.
*/
#define undoItem 1
#define cutItem 3
#define copyItem 4
#define pasteItem 5
#define clearItem 6
/*
* Items in Options Menu
*/
#define convertItem 1 /* Convert newlines */
#define doscvtItem 2 /* Convert DOS stype newlines */
#define oldArchItem 3 /* Old tar compatible archive creation */
#define floppyItem 4 /* Use floppy as archive file */
#define tapeItem 5 /* Use tape drive as archive file */
#define tapeOptItem 6 /* Tape SCSI ID dialog */
#define blockItem 7 /* Set block size */
#define overWriteItem 8 /* Force over write of files on extract */
#define pageItem 10 /* Control paging of screen listing */
#define printItem 11 /* Use printer instead of screen */
#define typeItem 13 /* Creator/Type dialog */
/*
* Menu related variables
*/
MenuHandle menus[menuCount];
Boolean menusOK;
/*
* MenuInit - set up menu bar
*
* Reads non-apple menus from resource file.
*/
Boolean
MenuInit() {
int i;
char *routine = "\pMenuInit";
if ((menus[appleMenu] = GetMenu(appleID)) == nil) {
OSAlert(routine, "\pGetMenu Apple Menu", nil, ResError());
return(true);
}
AddResMenu(menus[appleMenu], 'DRVR');
if ((menus[fileMenu] = GetMenu(fileID)) == nil) {
OSAlert(routine, "\pGetMenu File Menu", nil, ResError());
return(true);
}
if ((menus[editMenu] = GetMenu(editID)) == nil) {
OSAlert(routine, "\pGetMenu Edit Menu", nil, ResError());
return(true);
}
if ((menus[optionMenu] = GetMenu(optionID)) == nil) {
OSAlert(routine, "\pGetMenu Option Menu", nil, ResError());
return(true);
}
for (i = appleMenu; i < menuCount; i++)
InsertMenu(menus[i], 0);
DDaMenus();
/*
* Setup checkmarks from preferences.
*/
if (pref.tape && pref.floppy)
pref.floppy = false;
CheckItem(menus[optionMenu], convertItem, pref.cvtNl);
CheckItem(menus[optionMenu], doscvtItem, pref.dosCvt);
CheckItem(menus[optionMenu], oldArchItem, pref.oldArch);
CheckItem(menus[optionMenu], floppyItem, pref.floppy);
CheckItem(menus[optionMenu], pageItem, pref.autoPage);
CheckItem(menus[optionMenu], printItem, pref.doPrint);
CheckItem(menus[optionMenu], tapeItem, pref.tape);
DrawMenuBar();
return(false);
}
/*
* MenuCmd - handle a menu pick or keyboard equivalent
*/
MenuCmd(result)
long result;
{
WindowPeek wp;
short theItem = result & 0xffff;
short theMenu = (result >> 16) & 0xffff;
char name[256];
OSErr err;
char *routine = "\pMenuCmd";
GrafPtr savedPort;
switch (theMenu) {
case appleID:
if (theItem == aboutItem)
DoAboutBox();
else {
/*
* Oh boy, set up for a desk accessory.
*/
GetItem(menus[appleMenu], theItem, name);
GetPort(&savedPort);
if ((err = ZeroScrap()) != noErr) {
OSAlert(routine, "\pZeroScrap", nil, err);
break;
}
if ((err = TEToScrap()) != noErr) {
OSAlert(routine, "\pTEToScrap", nil, err);
break;
}
(void) OpenDeskAcc(name);
SetPort(savedPort);
if (FrontWindow() != nil) {
EDaMenus();
}
}
break;
case fileID:
switch (theItem) {
case createItem:
ArCreate();
break;
case extractItem:
Extract();
break;
case listItem:
List();
break;
case closeItem:
/*
* If the front window belongs to a Desk Acc, close it!
*/
if ((wp = (WindowPeek) FrontWindow()) == nil)
break;
if (wp->windowKind < 0) {
CloseDeskAcc(wp->windowKind);
DDaMenus();
}
break;
case pgsetItem:
if (!PrSetup())
(void) PrStlDialog(prRecHdl);
break;
case prefItem:
SavePreferences();
break;
case quitItem:
doneFlag = true;
break;
}
break;
case editID:
/*
* Send to a Desk Acc.
*/
(void) SystemEdit(theItem - 1);
break;
case optionID:
switch (theItem) {
case convertItem:
pref.cvtNl ^= true;
CheckItem(menus[optionMenu], convertItem, pref.cvtNl);
if (pref.cvtNl) {
pref.dosCvt = false;
CheckItem(menus[optionMenu], doscvtItem, pref.dosCvt);
}
break;
case doscvtItem:
pref.dosCvt ^= true;
CheckItem(menus[optionMenu], doscvtItem, pref.dosCvt);
if (pref.dosCvt) {
pref.cvtNl = false;
CheckItem(menus[optionMenu], convertItem, pref.cvtNl);
}
break;
case oldArchItem:
pref.oldArch ^= true;
CheckItem(menus[optionMenu], oldArchItem, pref.oldArch);
break;
case floppyItem:
pref.floppy ^= true;
CheckItem(menus[optionMenu], floppyItem, pref.floppy);
if (pref.floppy && pref.tape) {
pref.tape = false;
CheckItem(menus[optionMenu], tapeItem, pref.tape);
}
break;
case overWriteItem:
pref.doOverWrite ^= true;
CheckItem(menus[optionMenu], overWriteItem, pref.doOverWrite);
break;
case blockItem:
DoBlockSize();
break;
case pageItem:
pref.autoPage ^= true;
CheckItem(menus[optionMenu], pageItem, pref.autoPage);
break;
case printItem:
pref.doPrint ^= true;
CheckItem(menus[optionMenu], printItem, pref.doPrint);
break;
case typeItem:
DoCreatorType();
break;
case tapeItem:
pref.tape ^= true;
CheckItem(menus[optionMenu], tapeItem, pref.tape);
if (pref.tape && pref.floppy) {
pref.floppy = false;
CheckItem(menus[optionMenu], floppyItem, pref.floppy);
}
break;
case tapeOptItem:
DoTapeOptions();
break;
}
break;
}
HiliteMenu(0);
FlushEvents(everyEvent, 0);
}
/*
* DDaMenus - disable Desk Acc specific menu and menu item
*/
DDaMenus() {
DisableItem(menus[editMenu], 0);
DisableItem(menus[fileMenu], closeItem);
DrawMenuBar();
menusOK = true;
}
/*
* EDaMenus - enable Desk Acc specific menu and menu item
*/
EDaMenus() {
EnableItem(menus[editMenu], 0);
EnableItem(menus[fileMenu], closeItem);
DrawMenuBar();
menusOK = false;
}